package com.mdd.front.service.product.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdd.front.service.product.IProductSkuFrontService;
import com.mdd.front.vo.sku.ProductSkuVo;
import com.mdd.product.entity.ProductSku;
import com.mdd.product.mapper.ProductSkuMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 商品sku实现类
 * @author LikeAdmin
 */
@Service
public class ProductSkuFrontServiceImpl implements IProductSkuFrontService {

    @Resource
    ProductSkuMapper productSkuMapper;
    /**
     * 商品sku列表
     *
     * @author LikeAdmin
     * @return PageResult<ProductSkuListedVo>
     */
    @Override
    public List<ProductSkuVo> list(Long spuId) {
        LambdaQueryWrapper<ProductSku> productWrapper=new LambdaQueryWrapper<>();
        productWrapper.eq(ProductSku::getSpuId,spuId);
        List<ProductSku> data = productSkuMapper.selectList(productWrapper);

        List<ProductSkuVo> list = new LinkedList<>();
        for(ProductSku item : data) {
            ProductSkuVo vo = new ProductSkuVo();
            BeanUtils.copyProperties(item, vo);
            list.add(vo);
        }
        return list;
    }
}
